﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Transactions;

namespace Gatheshop.BLL
{
    public class GESTranScope : IDisposable
    {
        TransactionScope _transcope ;
        /// <summary>
        /// 创建SQL事务
        /// </summary>
        public GESTranScope()
        {            
            TransactionOptions transoption = new TransactionOptions();
            transoption.IsolationLevel = IsolationLevel.ReadCommitted;
            _transcope = new TransactionScope(TransactionScopeOption.Required,transoption);
        }
        /// <summary>
        /// 提交事务
        /// </summary>
        public void Complete()
        {
            _transcope.Complete();
        }

        protected virtual void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                if (disposing)
                {
                    // Release managed resources
                }

                // Release unmanaged resources
                _transcope.Dispose();

                m_disposed = true;
            }
        }
        private bool m_disposed;
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        ~GESTranScope()
        {
            Dispose(false);
        }       
    }
}
